﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.Utilities;
using NetDon.WebControls;
using NetDon.eBoss.Data.CollectionClasses;
using NetDon.eBoss.Data.EntityClasses;
using NetDon.eBoss.Data.HelperClasses;
using NetDon.eBoss.Portal.Common;

namespace NetDon.OA.Portal.Admin
{
    public partial class CommonWordsEdit : NetDonPage
    {
        #region Properties
        protected int CategoryId
        {
            get
            {
                return Parameters.GetInt32("Id");
            }
        }

        public int SiteCode
        {
            get { return Parameters.GetInt32("Site"); }
        }

        public int Id
        {
            get { return ViewState["Id"] == null ? 0 : Convert.ToInt32(ViewState["Id"]); }
            set
            {
                ViewState["Id"] = value;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                spanTitle.InnerText = "Htmltool分类: " + new HtmltoolcategoryruleEntity(CategoryId).Category + " Site: " +
                                      EnumUtilities.GetDescription((eBaySites)Enum.Parse(typeof(eBaySites), SiteCode.ToString()));

                CancelButton = btnReturn;
                BindDropDownLists();
               

                    var collection = new HtmltoolvocabularyCollection();
                    collection.GetMulti(HtmltoolvocabularyFields.Categoryruleid == CategoryId & HtmltoolvocabularyFields.Sitecode ==SiteCode);
                if(collection.Count >0)
                {
                    panelCustomInfo.DataSource = collection.FirstOrDefault();
                    panelCustomInfo.DataBind();

                    Id = collection.First().Id;

                }
                  
               


            }
        }



        private void BindDropDownLists()
        {

        }




        private bool save()
        {
            HtmltoolvocabularyEntity entity = null;
            if (Id > 0)
            {
                entity = new HtmltoolvocabularyEntity(Id);

            }
            else
            {
                entity = new HtmltoolvocabularyEntity();
            }
            entity.Titleword = txtTitleword.Text.Trim();
            entity.Materialword = txtMATERIALWORD.Text.Trim();
            entity.Sitecode = SiteCode;
            entity.Categoryruleid = CategoryId;
            entity.Save();
            return true;
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {

            if (save())
            {
                Success("保存成功!");
                CloseWindow(true);
            }



        }




    }

}